home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / titlbar.exe / READ.ME < prev    next >
Text File  |  1992-10-03  |  7KB  |  142 lines

  1.     An application I developed had the specification that the screen (ie
  2. TProgram) had to have a title bar at the top at all times. This was simple
  3. enough (description below), but I found that with the title above the menu
  4. bar, the mouse would enter the title region when moved to the top of the
  5. screen. This was quite annoying; anyone used to a standard TV-type interface
  6. (NOT Windows) is used to whipping the mouse to the top, 'diagonally' moving
  7. to a menu item, and clicking. With the mouse able to enter the title region,
  8. the user can't do this: you have to move the mouse down one row for it to
  9. be on the menu bar. I solved this problem, and present my solution here.
  10.     The solution involves modifying the original TV source code (in
  11. particular, TMOUSE.CPP and SYSTEM.H). For those of you who do not have the
  12. TV source code, I've included NEWMOUSE.OBJ (I can't include the TMOUSE.CPP
  13. modified code, since it is copyrighted material of Borland's); just include
  14. NEWMOUSE.OBJ in your project when building a TV application and (with the
  15. mods to SYSTEM.H) you will also be able to use this feature.
  16.     Discussion.
  17.     Using a title bar in a TV application can be very easy - or a bit
  18. difficult - depending on your needs. The easy part is just having a title
  19. bar at the top of the screen; all you need to do is derive a proper TView
  20. class (I use TStaticText), insert it into TProgram (at the top), adjust
  21. the menu bar and desktop, and you're done. Here's an example of a title bar
  22. class that is 1 row high and uses black-on-green and centered text:
  23. class TTitleBar : public TStaticText
  24.     {
  25.     public:
  26.         TTitleBar( const TRect& bounds, const char *aText );
  27.  
  28.         virtual TPalette& getPalette() const;
  29.     };
  30. The full declaration for this class can be found in TTITLBAR.H, and the
  31. definition in TTITLBAR.CPP. The concept here is that the title bar is just
  32. a TStaticText-type object, with getPalette() overridden to use the
  33. appropriate entry in TProgram's palette (since a standard TStaticText is
  34. designed to be inserted into a TDialog, its palette is probably not what
  35. you want your title bar to be). Since we want the title centered, we make
  36. sure that when TTitleBar's ctor is called, the aText argument has a leading
  37. '\003' character - this tells TStaticText to center the text.
  38.     In a normal application, the menubar has its origin member set to
  39. (0,0), and the desktop has its set to (0,1). This is reflected in the
  40. standard start of a normal initMenuBar(...) method:
  41. TMenuBar *TMyApp::initMenuBar( TRect r )
  42.     {
  43.     r.b.y = r.a.y+1;                // r.a = (0,0)
  44.     return new TMenuBar(r, ...);    // r = (0,0,80,1)
  45.     }
  46. and the normal initDeskTop(...) method:
  47. TDeskTop *TMyApp::initDeskTop( TRect r )
  48.     {
  49.     r.a.y++;
  50.     r.b.y--;
  51.     return new TDeskTop(r);            // r = (0,1,80,24)
  52.     }
  53. But our new title bar is going to occupy row 0, so these two methods have
  54. to be changed to accomodate it: this can be seen in TEST.CPP. We don't have
  55. to change initStatusLine(...) since it still occupies the bottom row of the
  56. screen.
  57.     This works fine, but the mouse can go into the title bar region; so now
  58. comes the 'bit difficult' part. If you examine SYSTEM.H, you'll see that
  59. the class TMouse has only one range-setting method (setRange(...)) and that
  60. it only takes 2 arguments: the new right and bottom ranges - the top and
  61. left are *assumed* to start at (0,0). So the first thing we have to do is
  62. modify TMouse (and THWMouse) to accept *at least* the top row as an argument,
  63. along with the right and bottom arguments. As a general method however,
  64. something like:
  65. void THWMouse::setRange( ushort top, ushort rx, ushort ry );
  66. is a bit restrictive - as long as we're making a method that will restrict
  67. the mouse range, we should make it comprehensive - allow it to have a full
  68. rectangular argument. This has the benefit of: if you want to restrict the
  69. mouse movement to a window on the screen, you can do so. But before I show
  70. the code changes that will implement this, we need to be cautious; there are
  71. a number of times when TV calls TMouse::setRange(rx,ry) (a bug fix for TV1.0
  72. <incorporated into TV1.03> calls setRange when TProgram::setScreenMode is
  73. called). An example of this is shown in TEST.CPP - the single menubar item
  74. File has a submenu item Change screen mode - it toggles from 25 to 43/50
  75. line mode. When the screen mode is changed,
  76.     TMouse::setRange( TScreen::screenWidth-1, TScreen::screenHeight-1 );
  77. is called - and our 'dead' mouse range in the title bar region goes away!
  78. We can fix this by also changing TMouse::setRange(ushort,ushort) so that,
  79. instead of using a default of (0,0) for the top-left coordinate, uses
  80. (mouseOffset.x, mouseOffset.y), where TPoint mouseOffset is (0,0) by default,
  81. but is changed when we make the setRange(const TRect&) call. Here's how all
  82. of this is done:
  83. [File: SYSTEM.H]
  84.     class THWMouse:
  85.         *add the following protected method:
  86.             static void setRange( const TRect& bounds );
  87.     class TMouse:
  88.         *add the following public method:
  89.             static void setRange( const TRect& bounds );
  90.     immediately following class TMouse:
  91.         * add the following inline definition:
  92.             inline void TMouse::setRange( const TRect& bounds )
  93.             {
  94.                 THWMouse::setRange(bounds);
  95.             }
  96. [File: TMOUSE.CPP]
  97.     near the top of the file:
  98.         *add the following static variable:
  99.             static TPoint mouseOffset = { 0, 0 };
  100.     method THWMouse::setRange(ushort,ushort):
  101.         *comment out the listed code and in its place use:
  102.             {
  103.                 setRange( TRect(mouseOffset.x,mouseOffset.y,rx,ry) );
  104.             }
  105.     just after THWMouse::setRange(ushort,ushort):
  106.         *add the following method:
  107.             void THWMouse::setRange( const TRect& bounds )
  108.             {
  109.             if( buttonCount != 0 )
  110.                 {
  111.                 TRect r = bounds;
  112.                 r.a.x <<= 3;
  113.                 r.a.y <<= 3;
  114.                 r.b.x <<= 3;
  115.                 r.b.y <<= 3;
  116.                 _DX = r.b.x;
  117.                 _CX = r.a.x;
  118.                 _AX = 7;
  119.                 geninterrupt( 0x33 );
  120.                 _DX = r.b.y;
  121.                 _CX = r.a.y;
  122.                 _AX = 8;
  123.                 geninterrupt( 0x33 );
  124.                 mouseOffset = bounds.a;
  125.                 }
  126.             }
  127. Note: if you do not have the TV source code, the file NEWMOUSE.OBJ that was
  128. included with this file contains the above changes in compiled form.
  129.  
  130.     The enclosed files TTitlbar.h and TTitlebar.cpp include the code for a
  131. title bar class. The enclosed file Test.cpp shows using this class to
  132. implement a title bar in an application, as well as using the modified
  133. TMouse class to keep the mouse cursor out of the title bar region. For
  134. demonstration purposes a menu entry allows you to swap from 25 to 43/50 line
  135. mode to show that the mouse restricted movement works as planned.
  136.     If, for some reason, you want to be able to read the mouseOffset value,
  137. add a new method to TMouse and have it return mouseOffset. I did not
  138. implement this because I could not see a use for this information. If you
  139. make other changes to TMouse and THWMouse, DO NOT (!) modify mouseOffset -
  140. use setRange() to do so.
  141.     Pat Reilly    700274,161
  142.